package com.ruoyi.food.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.food.domain.OpmFoodCompanyFile;
import com.ruoyi.food.service.IOpmFoodCompanyFileService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 企业安全档案Controller
 *
 * @author cjie
 * @date 2021-08-02
 */
@Api(tags = " 企业安全档案")
@RestController
@RequestMapping("/opmFoodCompanyFile")
public class OpmFoodCompanyFileController extends BaseController {
    @Autowired
    private IOpmFoodCompanyFileService opmFoodCompanyFileService;

    /**
     * 查询企业安全档案列表
     */
    @ApiOperation(value="查询企业安全档案列表", notes="查询企业安全档案列表")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:list")
    @GetMapping("/list")
    public TableDataInfo list(OpmFoodCompanyFile opmFoodCompanyFile) {
        startPage();
        List<OpmFoodCompanyFile> list = opmFoodCompanyFileService.selectOpmFoodCompanyFileList(opmFoodCompanyFile);
        return getDataTable(list);
    }

    /**
     * 导出企业安全档案列表
     */
    @ApiOperation(value="导出企业安全档案列表", notes="导出企业安全档案列表")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:export")
    @Log(title = "企业安全档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpmFoodCompanyFile opmFoodCompanyFile) throws IOException {
        List<OpmFoodCompanyFile> list = opmFoodCompanyFileService.selectOpmFoodCompanyFileList(opmFoodCompanyFile);
        ExcelUtil<OpmFoodCompanyFile> util = new ExcelUtil<OpmFoodCompanyFile>(OpmFoodCompanyFile.class);
        util.exportExcel(response, list, "企业安全档案数据");
    }
    /**
     * 获取企业安全档案详细信息
     */
    @ApiOperation(value="获取企业安全档案详细信息", notes="获取企业安全档案详细信息")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(opmFoodCompanyFileService.selectOpmFoodCompanyFileById(id));
    }

    /**
     * 新增企业安全档案
     */
    @ApiOperation(value="新增企业安全档案", notes="新增企业安全档案")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:add")
    @Log(title = "企业安全档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpmFoodCompanyFile opmFoodCompanyFile) {
        return toAjax(opmFoodCompanyFileService.insertOpmFoodCompanyFile(opmFoodCompanyFile));
    }

    /**
     * 修改企业安全档案
     */
    @ApiOperation(value="修改企业安全档案", notes="修改企业安全档案")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:edit")
    @Log(title = "企业安全档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpmFoodCompanyFile opmFoodCompanyFile) {
        return toAjax(opmFoodCompanyFileService.updateOpmFoodCompanyFile(opmFoodCompanyFile));
    }

    /**
     * 删除企业安全档案
     */
    @ApiOperation(value="删除企业安全档案", notes="删除企业安全档案")
    @ApiImplicitParam(name = "ids", value = "企业安全档案ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "food:opmFoodCompanyFile:remove")
    @Log(title = "企业安全档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(opmFoodCompanyFileService.deleteOpmFoodCompanyFileByIds(ids));
    }
}
